<?php

/**
 * This is the model class for table "{{user_extend}}".
 *
 * The followings are the available columns in table '{{user_extend}}':
 * @property string $intro
 * @property integer $uid
 * @property string $real_name
 * @property string $phone
 * @property string $weibo
 * @property string $qq
 * @property string $birthday
 * @property string $astro
 * @property string $job
 * @property integer $province
 * @property integer $city
 * @property integer $town
 * @property string $address
 * @property string $code
 */
class UserExtend extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{user_extend}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('uid', 'required'),
			array('uid, province, city, town', 'numerical', 'integerOnly'=>true),
			array('intro, address', 'length', 'max'=>255),
			array('real_name', 'length', 'max'=>20),
			array('phone, qq, birthday', 'length', 'max'=>15),
			array('weibo', 'length', 'max'=>40),
			array('astro', 'length', 'max'=>18),
			array('job', 'length', 'max'=>60),
			array('code', 'length', 'max'=>6),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('intro, uid, real_name, phone, weibo, qq, birthday, astro, job, province, city, town, address, code', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'intro' => 'Intro',
			'uid' => 'Uid',
			'real_name' => 'Real Name',
			'phone' => 'Phone',
			'weibo' => 'Weibo',
			'qq' => 'Qq',
			'birthday' => 'Birthday',
			'astro' => 'Astro',
			'job' => 'Job',
			'province' => 'Province',
			'city' => 'City',
			'town' => 'Town',
			'address' => 'Address',
			'code' => 'Code',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('intro',$this->intro,true);
		$criteria->compare('uid',$this->uid);
		$criteria->compare('real_name',$this->real_name,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('weibo',$this->weibo,true);
		$criteria->compare('qq',$this->qq,true);
		$criteria->compare('birthday',$this->birthday,true);
		$criteria->compare('astro',$this->astro,true);
		$criteria->compare('job',$this->job,true);
		$criteria->compare('province',$this->province);
		$criteria->compare('city',$this->city);
		$criteria->compare('town',$this->town);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('code',$this->code,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return UserExtend the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
